//获取当前系统时间
var util = require('../../utils/utils');
//引入用来发送的请求方法
import {
  request
} from "../../request/index.js"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    ccellss:'',
    time: util.formatDate(new Date()),//时间
    income: 0, //收入金额
    pay: 0, //支出金额
    popup3: false,
    multiIndex: [0, 0, 0],
    date: '全部',

    // 加号弹出
    isPopping: false, //是否已经弹出
    animPlus: {}, //旋转动画
    animCollect: {}, //item位移,透明度
    animTranspond: {}, //item位移,透明度
    animInput: {}, //item位移,透明度
    uid: "",
    select: [],
    bid: 0,

    right: [{
        text: '返回',
        style: 'background-color: #ddd; color: white',
      },
      {
        text: '删除',
        style: 'background-color: #F4333C; color: white',
      }
    ],
    left: [{
        text: 'Reply',
        style: 'background-color: #108ee9; color: white',
      },
      {
        text: '隐藏',
        style: 'background-color: #ddd; color: white',
      }
    ],
    uid: "",
    select: [],
    bid: 0,

    right: [{
        text: '返回',
        style: 'background-color: #ddd; color: white',
      },
      {
        text: '删除',
        style: 'background-color: #F4333C; color: white',
      }
    ],
    left: [{
        text: 'Reply',
        style: 'background-color: #108ee9; color: white',
      },
      {
        text: '隐藏',
        style: 'background-color: #ddd; color: white',
      }
    ],
  },
   // 监听页面是否到底部
   scrollToLower: function(e) {
    var that =this;
    wx.showToast({
      title: '到底啦！',
      image:'/icons/卡通.png'
    })
   
   

   
  },


  /**
   * 时间
   * @param {} e 
   */
  handleSelected(e) {
    var time = e.detail.value.format('YYYY-MM-DD');
    this.select(time);
    this.selectIncome(time);
    this.selectPay(time);
  },
  handleClose() {
    this.setData({
      popup3: false,
    });
  },
  handleClick3() {
    this.setData({
      popup3: true
    });
  },
  /**
   * 显示详情
   */
  seeDetail: function (e) {
    console.log(e);
    this.setData({
      bid: e.currentTarget.id
    });
    wx.navigateTo({
      url: '../pay/index?bid=' + this.data.bid,
    })
  },
  /**
   * 加号动画
   */
  //点击弹出
  plus: function () {
    if (this.data.isPopping) {
      //缩回动画
      this.popp();
      this.setData({
        isPopping: false
      })
    } else if (!this.data.isPopping) {
      //弹出动画
      this.takeback();
      this.setData({
        isPopping: true
      })
    }
  },
  input: function () {
    this.plus();
    console.log("添加")
    wx.showToast({
      title: '添加',
      icon: "none"
    })
  },
  transpond: function () {
    this.plus();
    console.log("打印")
    wx.showToast({
      title: '打印',
      icon: "none"
    })
  },
  collect: function () {
    this.plus();
    wx.showToast({
      title: '修改',
      icon: "none"
    })
    console.log("修改")
  },

  //弹出动画
  popp: function () {
    //plus顺时针旋转
    var animationPlus = wx.createAnimation({
      duration: 500,
      timingFunction: 'ease-out'
    })
    var animationcollect = wx.createAnimation({
      duration: 500,
      timingFunction: 'ease-out'
    })
    var animationTranspond = wx.createAnimation({
      duration: 500,
      timingFunction: 'ease-out'
    })
    var animationInput = wx.createAnimation({
      duration: 500,
      timingFunction: 'ease-out'
    })
    animationPlus.rotateZ(180).step();
    animationcollect.translate(-100, -100).rotateZ(180).opacity(1).step();
    animationTranspond.translate(-140, 0).rotateZ(180).opacity(1).step();
    animationInput.translate(-100, 100).rotateZ(180).opacity(1).step();
    this.setData({
      animPlus: animationPlus.export(),
      animCollect: animationcollect.export(),
      animTranspond: animationTranspond.export(),
      animInput: animationInput.export(),
    })
  },
  //收回动画
  takeback: function () {
    //plus逆时针旋转
    var animationPlus = wx.createAnimation({
      duration: 500,
      timingFunction: 'ease-out'
    })
    var animationcollect = wx.createAnimation({
      duration: 500,
      timingFunction: 'ease-out'
    })
    var animationTranspond = wx.createAnimation({
      duration: 500,
      timingFunction: 'ease-out'
    })
    var animationInput = wx.createAnimation({
      duration: 500,
      timingFunction: 'ease-out'
    })
    animationPlus.rotateZ(0).step();
    animationcollect.translate(0, 0).rotateZ(0).opacity(0).step();
    animationTranspond.translate(0, 0).rotateZ(0).opacity(0).step();
    animationInput.translate(0, 0).rotateZ(0).opacity(0).step();
    this.setData({
      animPlus: animationPlus.export(),
      animCollect: animationcollect.export(),
      animTranspond: animationTranspond.export(),
      animInput: animationInput.export(),
    })
  },
  /***
   * 键盘删除事件
   * 
   */
  delete(e) {
    console.log(e);
    console.log(this.data.bid),

      wx.showModal({
        title: '提示',
        content: '确定要删确认除吗？',
        success: (b) => {
          if (b.confirm) {
            console.log("删除");
            this.setData({
              bid: e.currentTarget.id
            });
            wx.request({
              url: 'http://localhost:8080/TheTimeSequence/BooksServlet?opr=del',
              data: {
                bid: this.data.bid
              },
              success: (e) => {
                this.onLoad();
                // wx.redirectTo({
                //   url: '../Bookkeeping/index',
                // })
              } 
            })
          } else if (e.cancel) {
            console.log('用户点击取消')
          }
        }
      })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    this.setData({
      uid: wx.getStorageSync('user').uid
    });
    if (this.data.uid == undefined) {
      wx.redirectTo({
          url: '../demo/index',
        }),
        wx.showToast({
          title: "请先登录！",
          icon: 'none',
          duration: 1000,
          mask: true
        })
    } else {
      this.select("");
      this.selectIncome();
      this.selectPay();
    }
    setTimeout(function() {
      that.setData({
        ccellss:'display:none'
      })
   }, 2000);
  },
  /**
   * 数据 渲染
   */
  select(time) {
    var _this = this
    wx.request({
      url: 'http://localhost:8080/TheTimeSequence/BooksServlet?opr=list',
      data: {
        uid: this.data.uid,
        time:time
      },
      success: function (res) {
        // console.log(res)
        _this.setData({
          select: res.data
        })
      }
    })
  },
  selectPay(time){
    var _this = this
    wx.request({
      url: 'http://localhost:8080/TheTimeSequence/BooksServlet?opr=amount',
      data: {
        uid: this.data.uid,
        sid:1,
        time:time
      },
      success: function (res) {
        // console.log(res)
        _this.setData({
          pay: res.data
        })
      }
    })
  },
  
  selectIncome(time){
    // console.log(time);
    var _this = this
    wx.request({
      url: 'http://localhost:8080/TheTimeSequence/BooksServlet?opr=amount',
      data: {
        uid: this.data.uid,
        sid:2,
        time:time
      },
      success: function (res) {
        // console.log(res)
        _this.setData({
          income: res.data
        })
      }
    })
  },
 
})